package com.yc.spring.bank.dao;

import com.yc.spring.bank.bean.Record;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

@Repository
public class RecordDao {

    @Resource
    JdbcTemplate jdbcTemplate;

    public int insert(Record record) {
        String sql = "insert into bank_oprecord values(?,?,?,?,?,?)";
        return jdbcTemplate.update(sql,
                record.getId(),
                record.getAid(),
                record.getOpmoney(),
                record.getCharge(),
                new Timestamp(System.currentTimeMillis()),
                record.getRemark());
    }

    public List<Record> selectByAidAndDate(
            String aid, Timestamp begin, Timestamp end) {
        String sql = "select * from bank_account where aid=?" +
                " and optime between ? and ?";
        return jdbcTemplate.query(sql,
                new BeanPropertyRowMapper<Record>(Record.class),
                aid, begin, end);
    }


}
